package com.mvp.shq.washer.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mvp.shq.washer.R;
import com.mvp.shq.washer.entity.Coupon;
import com.mvp.shq.washer.rxbus.RxBus;
import com.mvp.shq.washer.utils.EventCode;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/1.
 */

public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.ViewHolder> {

    private Context context;
    private List<Coupon> coupons;

    public CouponAdapter(Context mContext, List<Coupon> list) {
        context = mContext;
        coupons = list;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_coupon, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Coupon coupon = coupons.get(position);
        if (coupon.getShowStatus().equals("0") || coupon.getShowStatus().equals("1")){
            holder.imgCouponBg.setImageResource(R.mipmap.ticket_accessible);
        }else if (coupon.getShowStatus().equals("2")){
            holder.imgCouponBg.setImageResource(R.mipmap.ticket_overdue);
        }else if (coupon.getShowStatus().equals("3")){
            holder.imgCouponBg.setImageResource(R.mipmap.ticket_used);
        }
        holder.tvTime.setText(coupon.getTime());
        String couponName = "";
        String type = coupon.getCouponType();
        if ("0".equals(type)){
            couponName = "强力";
        }else if ("1".equals(type)){
            couponName = "标准";
        }else if ("2".equals(type)){
            couponName = "快速";
        }else if ("3".equals(type)){
            couponName = "单脱";
        }else if ("4".equals(type)){
            couponName = "通用";
        }
        holder.tvPatternName.setText(couponName);
        holder.imgCouponBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RxBus.get().send(EventCode.ON_COUPON_CLICK,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return coupons.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_coupon_bg)
        ImageView imgCouponBg;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_pattern_name)
        TextView tvPatternName;
        @BindView(R.id.tv_pattern_model)
        TextView tvPatternModel;
        @BindView(R.id.tv_pattern_type)
        TextView tvPatternType;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            AutoUtils.autoSize(itemView);
        }
    }
}
